using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace DrawImageSample
{
    public partial class ScreenThumbnail : UserControl
    {
        public static event EventHandler SelectionChanged;

        public ScreenThumbnail(Image pImage, string pLabel)
        {
            InitializeComponent();

            this.mImage.Image = pImage;
            this.mLabel.Text = pLabel;
        }

        public string Label
        {
            get
            {
                return this.mLabel.Text;
            }
            
            set
            {
                this.mLabel.Text = value;
            }
        }

        public Image Image
        {
            get
            {
                return this.mImage.Image;
            }
        }

        private static ScreenThumbnail sSelectedThumbnail;
        public void SelectThumbnail()
        {
            if (sSelectedThumbnail != this)
            {
                if (sSelectedThumbnail != null)
                {
                    sSelectedThumbnail.BackColor = SystemColors.Control;
                }

                sSelectedThumbnail = this;
                sSelectedThumbnail.BackColor = Color.Red;
                SelectionChanged.Invoke(this, new EventArgs());
            }
        }

        private void ScreenThumbnail_Click(object sender, EventArgs e)
        {
            this.SelectThumbnail();
        }

        private void mImage_Click(object sender, EventArgs e)
        {
            this.SelectThumbnail();
        }

        private void mLabel_Click(object sender, EventArgs e)
        {
            this.SelectThumbnail();
        }
    }
}
